<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_imgs/model')->方法名();
*/
namespace jy_imgs;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function pdf2png($pdf='', $path='',$imgs=array()){
        if (!extension_loaded('imagick')) {
           exi('请先安装PHP imagemagick扩展！','error');
        }
		$pdf=ROOT_AT.$pdf;
        if (!file_exists($pdf)) {
            exi('请上传PDF文件！','error');
        }
        $im = new \Imagick();
        $im->setResolution(72, 72); //设置分辨率 值越大分辨率越高
        $im->setCompressionQuality(100);
        $im->readImage($pdf);
		$i=0;
        foreach($im as $k => $v) {
			$filename=$imgs[$i]?:cfc('files')->get_source_name('image','png');
			$pathimage=$path?:ROOT_AT.$filename;
            $v->setImageFormat('png');
            $fileName2 = $pathimage;
            if ($v->writeImage($fileName2) == true) {
                $return[] = $filename;
				$i++;
            }
        }
        return $return;
    }
}
?>